import Point from "./Point";

const enum N {
    /** PI/180 */
    $PI_180 = 0.017453292519943295,
    /** 180/PI */
    $180_PI = 57.29577951308232,
}

/** 物体基类 */
export default abstract class Base extends Point {

    protected _w: number
    protected _h: number
    protected _a: number

    constructor(cfg: { x?: number, y?: number, w?: number, h?: number, a?: number } = {}) {
        super(cfg)
        this._w = cfg.w || 0
        this._h = cfg.h || 0
        this._a = cfg.a || 0
    }

    /** 宽度 */
    get w() { return this._w }
    set w(v) { this._w = v }
    /** 高度 */
    get h() { return this._h }
    set h(v) { this._h = v }
    /** 角度 */
    get a() { return this._a }
    set a(v) { this._a = v < 0 ? 360 + v % 360 : v % 360 }
    /** 弧度 */
    get rad() { return this._a * N.$PI_180 }
    set rad(v) { this.a = v * N.$180_PI }

    /** 拷贝 */
    abstract cp(): this
    /** 拷贝坐标点 */
    cpp() { return super.cp() }
}